package me.mock.ingress;

import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;
import android.content.ContentResolver;
import android.location.LocationListener;
import android.location.LocationManager;
import android.provider.Settings.Secure;
import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;

public class LoadPackageHook implements IXposedHookLoadPackage
{

	private static final String SECURE_CLASS = Secure.class.getName();
	private static final String LOCATION_MANAGER_CLASS = LocationManager.class.getName();

	@Override
	public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable
	{
		if (!lpparam.packageName.equals("com.nianticproject.ingress"))
			return;

		XposedBridge.log("ingress package loaded");

		findAndHookMethod(SECURE_CLASS, lpparam.classLoader, "getFloat", ContentResolver.class, String.class,
				float.class, new GetSecureSettingsHook());

		findAndHookMethod(SECURE_CLASS, lpparam.classLoader, "getFloat", ContentResolver.class, String.class,
				new GetSecureSettingsHook());

		findAndHookMethod(SECURE_CLASS, lpparam.classLoader, "getInt", ContentResolver.class, String.class,
				new GetSecureSettingsHook());

		findAndHookMethod(SECURE_CLASS, lpparam.classLoader, "getInt", ContentResolver.class, String.class, int.class,
				new GetSecureSettingsHook());

		findAndHookMethod(SECURE_CLASS, lpparam.classLoader, "getLong", ContentResolver.class, String.class,
				long.class, new GetSecureSettingsHook());

		findAndHookMethod(SECURE_CLASS, lpparam.classLoader, "getLong", ContentResolver.class, String.class,
				new GetSecureSettingsHook());

		findAndHookMethod(SECURE_CLASS, lpparam.classLoader, "getString", ContentResolver.class, String.class,
				new GetSecureSettingsHook());

		findAndHookMethod(LOCATION_MANAGER_CLASS, lpparam.classLoader, "requestLocationUpdates", String.class,
				long.class, float.class, LocationListener.class, new RequestLocationUpdateRequestHook());
	}
}
